package com.twu.biblioteca.Actions;

import com.twu.biblioteca.Interfaces.MenuItems;
import com.twu.biblioteca.Models.BookCollection;
import com.twu.biblioteca.Models.MovieCollection;
import com.twu.biblioteca.Models.User;
import com.twu.biblioteca.Models.UserList;

import java.util.ArrayList;
import java.util.List;

public class Menu
{
    private List<String> menuItems = new ArrayList<String>();
    private String menuPrompt;
    private BookCollection bookCollection = new BookCollection();
    private UserList userList = new UserList();
    private MovieCollection movieCollection = new MovieCollection();

    private BookLister bookLister;

    public Menu()
    {
        menuItems.add("0: Login");
        menuItems.add("1: View all books");
        menuItems.add("2: View available books");
        menuItems.add("3: Reserve a book");
        menuItems.add("4: View all Movies");
        menuItems.add("5: See movie details");
        menuItems.add("6: Check your membership details");
        menuItems.add("7: Exit Biblioteca");
        menuPrompt = "Please enter your choice:";
    }

    public void printMenu()
    {
        System.out.println("Menu---------------------");
        for (String item : menuItems)
        {
            System.out.println(item);
        }
        System.out.print(menuPrompt);
    }


    public MenuItems selectMenuItem(String selection)
    {
        //get current logged in user
        User user = userList.getCurrentActiveUser();
        MenuItems menuItems;
        menuItems = new InValidActionReporter();
        switch(Integer.parseInt(selection))
        {
            case 0:
            {
                if(user!= null && user.getLoggedIn() == true)
                {
                    System.out.println("Invalid operation! Already logged in!");
                    menuItems = new InValidActionReporter();
                }
                else
                    menuItems = new UserLogin(userList);
            }
            break;

            case 1:
                menuItems = new BookLister(bookCollection,true);
                break;
            case 2:
                if(user!= null)   menuItems = new BookLister(bookCollection,false);
                break;
            case 3:
                if(user!= null)   menuItems = new BookReserver(bookCollection);
                break;
            case 4:
                menuItems = new AllMovieLister(movieCollection);
                break;
            case 5:
                if(user!= null)   menuItems = new MovieDetailLister(movieCollection);
                break;
            case 6:
                menuItems = new LibraryNumberRequester(user);
                break;
            case 7:
                menuItems = new Exit();
                break;
            default:
                menuItems = new InValidActionReporter();
        }
        return menuItems;
    }
}
